package com.hibase.core.excel.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.excel.entity.MdsExcelBizDataDetail;
import com.hibase.core.excel.service.MdsExcelBizDataDetailService;
import com.hibase.core.excel.vo.bizdata.detail.*;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Excel业务数据明细管理
 *
 * @author <a href="mailto:xiongliyi@hichain.com">Ian Xiong</a>
 * @since 1.4.50-V2
 */
@AllArgsConstructor
@Api(value = "mds-excel-bizDataDetail", tags = "Excel业务数据明细管理")
@RequestMapping("/mds-excel-bizDataDetail")
@RestController
public class MdsExcelBizDataDetailController {

    private final MdsExcelBizDataDetailService mdsExcelBizDataDetailService;

    @ApiOperation("分页查询")
    @HibasePostRequestMapping("/queryPage")
    public ResponseModel<MdsExcelBizDataDetailListVO> queryPage(@RequestBody MdsExcelBizDataDetailSearchVO searchVO) {
        PageInfo page = mdsExcelBizDataDetailService.queryPage(searchVO);
        page.setList(EntityUtil.transform(page.getList(), MdsExcelBizDataDetailListVO.class));
        return ResponseModel.successMsg(page);
    }


    @ApiOperation("分页查询")
    @HibasePostRequestMapping("/list")
    public ResponseModel<MdsExcelBizDataDetailListVO> queryPageByTemplateId(@RequestBody MdsExcelBizDataDetailByImportTemplateSearchVO searchVO) {
        PageInfo page = mdsExcelBizDataDetailService.queryPageByTemplateId(searchVO);
        page.setList(EntityUtil.transform(page.getList(), MdsExcelBizDataDetailListVO.class));
        return ResponseModel.successMsg(page);
    }

    @ApiOperation("新增记录")
    @HibasePostRequestMapping("/save")
    public ResponseModel<String> save(@RequestBody MdsExcelBizDataDetailInsertVO insertVO) {
        MdsExcelBizDataDetail entity = EntityUtil.transform(insertVO, MdsExcelBizDataDetail.class);
        entity.setFieldType(insertVO.getFieldType().getKey());
        mdsExcelBizDataDetailService.saveBizDataDetail(entity);
        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation("更新记录")
    @HibasePostRequestMapping("/update")
    public ResponseModel<String> update(@RequestBody MdsExcelBizDataDetailUpdateVO updateVO) {
        MdsExcelBizDataDetail entity = EntityUtil.transform(updateVO, MdsExcelBizDataDetail.class);
        entity.setFieldType(updateVO.getFieldType().getKey());
        mdsExcelBizDataDetailService.updateBizDataDetail(entity);
        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation("详情查询")
    @HibasePostRequestMapping("/detail")
    public ResponseModel<MdsExcelBizDataDetailViewVO> detail(@RequestBody OperationIdEntity operationIdEntity) {
        MdsExcelBizDataDetail entity = mdsExcelBizDataDetailService.getById(operationIdEntity.getId(), Boolean.TRUE);
        return ResponseModel.successMsg(EntityUtil.transform(entity, MdsExcelBizDataDetailViewVO.class));
    }


}
